package com.nhii.appframe.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.gyf.immersionbar.ImmersionBar;
import com.jess.arms.base.BaseNoTitleActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.nhii.appframe.di.component.DaggerLoginComponent;
import com.nhii.appframe.mvp.contract.LoginContract;
import com.nhii.appframe.mvp.presenter.LoginPresenter;
import com.nhii.base.common.core.ProjectConstants;
import com.nhii.base.common.routerBean.RouterHub;
import com.nhii.base.common.utils.SPUtils;
import com.nhii.base.common.utils.ToastUtil;
import com.nhii.mc.R;


import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * ================================================
 * author : Alex
 * e-mail : xys9786@outlook.com
 * version: 1.0
 * Description: 登录页面
 * <p>
 * Created by MVPArmsTemplate on 05/05/2020 08:03
 * ================================================
 */
@Route(path = RouterHub.APP_LOGINACTIVITY)
public class LoginActivity extends BaseNoTitleActivity<LoginPresenter> implements LoginContract.View {

    @BindView(R.id.login_username)
    EditText loginUsername;

    @BindView(R.id.login_pwd)
    EditText loginPwd;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLoginComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    /**
     * 重新加载的方法
     *
     * @param v
     */
    @Override
    protected void onNetReload(View v) {

    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        //设置全屏
        ImmersionBar.with(this).keyboardEnable(true).init();

        SPUtils.put(ProjectConstants.COMMON_ISLOGIN, "false");
    }

    @OnClick({R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:  //登录
                mPresenter.sentLogin(loginUsername.getText().toString(), loginPwd.getText().toString());
                break;
        }
    }

    @Override
    public void showMessage(@NonNull String message) {
        switch (message) {
            case "登录成功":
                ArmsUtils.startActivity(MainActivity.class);
                break;
            case "登录失败":
                ArmsUtils.startActivity(MainActivity.class);
                break;
        }

    }


}
